<template>
  <div class="rightBodyContent">
    <div class="rightBodyContent-in">
      <div class="hearder-search">
        <div class="mb-10">
          <el-button type="primary" @click="showDetailFn('')" size="small"><i class="el-icon-plus"></i>新增本周计划
          </el-button>
          <span class="ml-10"><i class="el-icon-warning-outline mr-5" style="color:#eca32e"></i>本周计划只有班级老师/班主任可添加</span>
        </div>
      </div>
      <!--本体列表，数据 -->
      <el-table
          ref="multipleTable"
          :data="arryList"
          :stripe="tableStripe"
          :border="tableBorder"
          tooltip-effect="dark"
          header-cell-class-name="table-text-c"
          cell-class-name="table-text-c">
        <el-table-column
            align="center"
            prop="id"
            label="校周">
          <template slot-scope="scope">
            <span v-if="scope.row.semester">
              {{ scope.row.semester.year}}学年{{ scope.row.semester.type == 1 ? '下' : '上' }}/{{ scope.row.teach_week }}周
            </span>
            <span v-else>
              未知
            </span>
          </template>
        </el-table-column>
        <el-table-column
            align="center"
            prop="name"
            label="课表">
          <template slot-scope="scope">
            <el-button type="primary" plain @click="showFileFn(scope.row.curriculum)" size="mini">查询课表详情</el-button>
          </template>
        </el-table-column>
        <el-table-column
            align="center"
            prop="id"
            label="班级"
            width="120">
          <template slot-scope="scope">
            {{ scope.row.classes.class_name }}
          </template>
        </el-table-column>
        <el-table-column
            align="center"
            label="创建人"
            width="140">
          <template slot-scope="scope">
            {{ scope.row.users.realname }}
          </template>
        </el-table-column>
        <el-table-column
            align="center"
            label="创建时间"
            width="140">
          <template slot-scope="scope">
            {{ scope.row.update_time }}
          </template>
        </el-table-column>
        <el-table-column
            align="center"
            label="操作"
            width="180">
          <template slot-scope="scope">
            <el-button plain size="mini" @click="showDetailFn(scope.row.id)">查看编辑</el-button>
            <el-button plain size="mini" @click="detelDetailFn(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--工具条 分页-->
      <el-col :span="24" class="toolbar">
        <el-pagination
            background
            :page-size="page.pagesize"
            :current-page="page.pageindex"
            layout="total, prev, pager, next"
            :total="page.total"
            @current-change="handleSizeChange"></el-pagination>
      </el-col>
    </div>
    <div class="height40"></div>
    <addweek :visible.sync="addWeekVisible" @InitFn="InitFn" :weekId="weekId"></addweek>
    <previewFile :visible.sync="previewVisible" :iframeSrc="iframeSrc"></previewFile>
  </div>
</template>

<script>
import {pagination} from '@/utils/util.js'
import standardList from "@/components/standard/standardList";


export default {
  components: {
    standardList
  },
  data() {
    return {
      tableStripe: true, // 是否斑马栏
      tableBorder: true, // 单元格右边边框
      arryList: [], // 数据列表
      // 页数
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      addWeekVisible: false,
      editForm: {},
      previewVisible: false,
      iframeSrc: '',
      weekId: 0
    }
  },
  created() {
    this.InitFn()
  },
  methods: {
    // 初始化
    InitFn() {
      this.editForm.p = this.page.pageindex
      this.$fetch(this.api.curriculum.index, this.editForm).then((response) => {
        if (response.code === 0) {
          for (let i in response.list.data) {
            response.list.data[i].update_time = response.list.data[i].update_time.split(' ')[0]
          }
          this.arryList = response.list.data
          this.page.total = response.list.total
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    handleSelectionChange(val) {
      this.handleSelection = val
    },
    // 搜索
    searchBtn() {
      this.page.pageindex = 1
      this.InitFn()
    },
    // 刷新页面
    refreshFn() {
      this.editForm.name = ''
      this.page.pageindex = 1
      this.editForm.start_time = ''
      this.editForm.end_time = ''
      this.addtime = []
      this.InitFn()
    },
    detelDetailFn(id) {
      this.$confirm('确认永久删除该课表, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.detelRespon(id)
      }).catch(() => {
      })
    },
    detelRespon(id) {
      this.$post(this.api.curriculum.delete, {
        id: id,
      }).then((response) => {
        this.InitFn()
      }).catch((err) => {
        console.log(err)
      })
    },
    standarFn(type) {
      this.standardvisible = true
      this.standardtype = type
    },
    showFileFn(fileSrc) {
      this.iframeSrc = fileSrc;
      this.previewVisible = true;
    },
    showDetailFn(id) {
      this.weekId = id;
      this.addWeekVisible = true;
    }
  },
  mounted() {
  },
}
</script>

